package com.example.demo.mapper;


import com.example.demo.entity.Music;
import com.example.demo.entity.NoteComment;
import com.example.demo.entity.NoteCreate;
import com.example.demo.vo.ViewNoteCommentInfo;
import com.example.demo.vo.ViewNoteCreateInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface NoteCreateMapper {

    @Select("select note_create_tb.*,u.user_name from note_create_tb join user_tb u on note_create_tb.user_id = u.user_id where note_status = #{note_status} order by note_create_tb.create_time DESC")
    List<ViewNoteCreateInfo> findNoteCreateInfostatus(@Param("note_status") String note_status);

    //笔记信息与用户信息相关联（不分页）,获取用户所有信息
    @Select("select note_create_tb.*,u.* from note_create_tb join user_tb u on note_create_tb.user_id = u.user_id where note_create_id=#{note_create_id}")
    List<ViewNoteCreateInfo> findNoteCreateUserId(@Param("note_create_id") Integer note_create_id);

    //笔记表和用户表关联：获取用户名以及用户头像
    @Select("select note_create_tb.*,u.user_name,u.profile_picture from note_create_tb join user_tb u on note_create_tb.user_id = u.user_id ")
    List<ViewNoteCreateInfo> findNoteCreateInfouser();

    @Select("SELECT * FROM note_create_tb ORDER BY view_count DESC")
    List<NoteCreate> findNoteCreateByview_count();

    @Select("select * from note_create_tb")
    List<NoteCreate> findNoteCreateAll();

    @Select("select * from note_create_tb where note_create_id=#{note_create_id}")
    NoteCreate findNoteCreateDyId(Integer note_create_id);


    //根据用户ID和笔记状态查找筛选数据
    @Select("SELECT n.*, u.user_name FROM note_create_tb n JOIN user_tb u ON n.user_id = u.user_id WHERE n.note_status = #{note_status} AND n.user_id = #{user_id}")
    List<ViewNoteCreateInfo> findNoteCreateinfoByStatusAndUser(@Param("note_status") String note_status, @Param("user_id") Integer user_id);

    //根据笔记ID筛选数据
    @Select("select note_create_tb.*,u.user_name from note_create_tb join user_tb u on note_create_tb.user_id = u.user_id where note_create_id=#{note_create_id}")
    ViewNoteCreateInfo  findNoteCreateinfoId(Integer note_create_id);

    //插入内容
    @Insert("insert into note_create_tb(user_id,title,note_content,note_type,note_status,image,like_count,view_count,comment_count) values (#{user_id},#{title},#{note_content},#{note_type},#{note_status},#{image},#{like_count},#{view_count},#{comment_count})")
    Integer insertNoteCreate(NoteCreate noteCreate);

    //修改点赞量等
    @Update("update note_create_tb set like_count=#{like_count},comment_count=#{comment_count} where note_create_id=#{note_create_id}")
    Integer updateNoteCreate(NoteCreate noteCreate);


    @Update("UPDATE note_create_tb SET note_status = #{note_status} WHERE note_create_id = #{note_create_id}")
    Integer updateNoteStatus(@Param("note_create_id") Integer note_create_id, @Param("note_status") String note_status);


    //修改笔记状态为审核通过
    @Update("UPDATE note_create_tb SET note_status = '审核通过' WHERE note_create_id = #{note_create_id}")
    Integer updateNoteStatus1(NoteCreate noteCreate);

    //修改笔记状态为审核未通过
    @Update("UPDATE note_create_tb SET note_status = '审核未通过' WHERE note_create_id = #{note_create_id}")
    Integer updateNoteStatus2(NoteCreate noteCreate);

    //修改笔记状态为待审核
    @Update("UPDATE note_create_tb SET note_status = '待审核' WHERE note_create_id = #{note_create_id}")
    Integer updateNoteStatus3(NoteCreate noteCreate);

    //修改笔记内容
    @Update("UPDATE note_create_tb SET title = #{title},note_content=#{note_content},note_type=#{note_type},image=#{image} where note_create_id=#{note_create_id}")
    Integer updateNoteCreate1(NoteCreate noteCreate);

    @Delete("delete from note_create_tb where note_create_id=#{note_create_id}")
    Integer deleteNoteCreate(Integer note_create_id);


    // 根据笔记状态和用户ID计数
    @Select("SELECT COUNT(*) FROM note_create_tb WHERE note_status = #{note_status} AND user_id = #{user_id}")
    Integer countPublishedNotesByStatus(@Param("note_status") String note_status, @Param("user_id") Integer user_id);


    //点击量(点击笔记浏览量)
    @Update("UPDATE note_create_tb SET view_count = view_count + 1 WHERE note_create_id = #{note_create_id}")
    Integer incrementViewCount(@Param("note_create_id") Integer note_create_id);

}
